//
// Created by iris on 24-11-4.
//

#include "CodeGen/CodeGenerator.h"

#include "CodeGen/CGModule.h"

#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/Support/raw_ostream.h"

using namespace codegen;

CodeGenerator *CodeGenerator::create(llvm::LLVMContext &Ctx, llvm::TargetMachine *TM) {
    return new CodeGenerator(Ctx, TM);
}

std::unique_ptr<llvm::Module> CodeGenerator::run(std::vector<ASTBase*> *Mod, std::string FileName) {
    std::unique_ptr<llvm::Module> M = std::make_unique<llvm::Module>(FileName, Ctx);
    M->setTargetTriple(TM->getTargetTriple().getTriple());
    M->setDataLayout(TM->createDataLayout());
    CGModule CGM(M.get());
    CGM.run(Mod);
    return M;
}
